import React, { useState, useEffect } from "react";
import { Row, Col, Spin } from 'antd'  
import Link from "next/link";
import ShareBox from "./shareBox";
import axios from "axios";
import RightAids from "../rightAids/rightAids";

import Header from "../../components/Header";

const Home = (props) => {
  const [mylist, setMylist] = useState();
  const [spinning, setSpinning] = useState(false); // loading
  useEffect(() => {
    getInitialProps()
  },[])
  const getInitialProps = () => {
    setSpinning(true)
    axios("http://127.0.0.1:7001/default/getShareTopicList").then((res) => {
      setMylist(res.data.data)
      
      setSpinning(false)
    })
  }
  return (
    <div className="appBox">
      <Header />
      <Spin tip="Loading..." spinning={ spinning }>
        <Row className="left-nav" type="flex" justify="space-around">
          <Col
            xs={22}
            sm={18}
            md={15}
            lg={15}
            xl={16}
            style={{ background: "#fff" }}
          >
            {mylist?mylist.map((res, index) => {
              console.log('9999999',JSON.stringify(res));
              
              return (
                // <Link to={{pathname:`/share/shareItem?Id=${res.id}`,state:222222222}}>
                <Link key={index} href={`/share/shareItem?info=${JSON.stringify(res.id)}`} as={`/share/shareItem?id=${res.id}`}>
                  <a>
                    <ShareBox shareList={res} key={index} />
                  </a>
                </Link>
              );
            }):""}
          </Col>
          <Col xs={0} sm={4} md={7} lg={7} xl={6}>
            <RightAids />
          </Col>
        </Row>
      </Spin>
    </div>
  );
};
// Home.getInitialProps = async (context) => {
//   // let baiduData = []
//   const promise = new Promise((resolve) => {
//     axios("http://127.0.0.1:7001/default/getShareTopicList").then((res) => {
//       // console.log(res.data,"666666666666",baiduData)
//       resolve(res.data);
//     });
//   });
//   return await promise;
// };
export default Home;
